//
//  SportsTableViewCell.m
//  LPSNews
//
//  Created by luffy on 14-10-23.
//  Copyright (c) 2014年 LPS. All rights reserved.
//

#import "SportsTableViewCell.h"
#import "UIImageView+WebCache.h"
@implementation SportsTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor colorWithRed:249/255.0 green:249/255.0 blue:249/255.0 alpha:1.0];
        
        UIImageView * sportsImageView = [[UIImageView alloc] init];
        UILabel * sportsTitle = [[UILabel alloc] init];
        UILabel * sportsAccessibilityLabel = [[UILabel alloc] init];
        UIView * techBottomLine = [[UIView alloc] init];
        
        self.spoImageView = sportsImageView;
        self.titleLabel = sportsTitle;
        self.sportsAccessibilityLabel = sportsAccessibilityLabel;
        self.techBottomLine = techBottomLine;
        
        [self addSubview:sportsImageView];
        [self addSubview:sportsTitle];
        [self addSubview:sportsAccessibilityLabel];
        [self addSubview:techBottomLine];
        
        [sportsAccessibilityLabel release];
        [sportsImageView release];
        [sportsTitle release];
        [techBottomLine release];
        
    }
    return self;
}
- (void)setSports:(SportsModel *)sports
{
    //    if (sports.number == 0) {
    //        UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 200)];
    //        self.spoImageView = imageView;
    //
    //        imageView.image = sports.picImage;
    //        [self.contentView addSubview:imageView];
    //        [imageView release];
    //
    //        UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 200, 310, 30)];
    //        titleLabel.text = sports.title;
    //        self.titleLabel = titleLabel;
    //        titleLabel.font = [UIFont systemFontOfSize:12];
    //        [self.contentView addSubview:titleLabel];
    //        [titleLabel release];
    //    }else
    //    {
    //        if (sports.imgType == 1) {
    //            UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 310, 30)];
    //            titleLabel.text = sports.title;
    //            self.titleLabel = titleLabel;
    //            titleLabel.font = [UIFont systemFontOfSize:12];
    //            [self.contentView addSubview:titleLabel];
    //            [titleLabel release];
    //
    //            UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 30, 300,100)];
    //            self.spoImageView = imageView ;
    //            imageView.image = sports.picImage;
    //            [self.contentView addSubview:imageView];
    //            [imageView release];
    //
    //            UILabel * digestLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 130, 300, 30)];
    //            digestLabel.text = sports.digest;
    //            digestLabel.font = [UIFont systemFontOfSize:12];
    //            digestLabel.numberOfLines = 0;
    //            self.digestLabel = digestLabel;
    //            digestLabel.textColor = [UIColor grayColor];
    //            [self.contentView addSubview:digestLabel];
    //            [digestLabel release];
    //        }else
    //        {
    //            UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 80, 60)];
    //            self.spoImageView = imageView ;
    //            imageView.image = sports.picImage;
    //            [self.contentView addSubview:imageView];
    //            [imageView release];
    //
    //            UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 0, 220, 30)];
    //            titleLabel.text = sports.title;
    //            self.titleLabel = titleLabel;
    //            titleLabel.font = [UIFont systemFontOfSize:12];
    //            [self.contentView addSubview:titleLabel];
    //            [titleLabel release];
    //
    //            UILabel * digestLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 30, 220, 30)];
    //            digestLabel.text = sports.digest;
    //            digestLabel.font = [UIFont systemFontOfSize:12];
    //            digestLabel.numberOfLines = 0;
    //            self.digestLabel = digestLabel;
    //            digestLabel.textColor = [UIColor grayColor];
    //            [self.contentView addSubview:digestLabel];
    //            [digestLabel release];
    //        }
    //    }
    [self.spoImageView sd_setImageWithURL:[NSURL URLWithString:sports.imgsrc] placeholderImage:[UIImage imageNamed:@"placeholderImage"] options:SDWebImageProgressiveDownload];
    
    // 判断是否为第一个ROW
    if (sports.number == 0) {
        // 第一个大图
        CGSize tempsize = CGSizeMake(320, 185);
        self.spoImageView.frame = (CGRect){CGPointZero,tempsize};
        
        // 大图的文字
        self.titleLabel.text = sports.title;
        self.titleLabel.frame = CGRectMake(14,CGRectGetMaxY(self.spoImageView.frame) + 1, [UIScreen mainScreen].bounds.size.width -20, 25);
        self.titleLabel.font = [UIFont systemFontOfSize:12];
        
    }else{
        if (sports.imgType == 1) {
            // 主标题
            self.titleLabel.text = sports.title;
            self.titleLabel.font = [UIFont systemFontOfSize:13];
            self.titleLabel.frame = CGRectMake(10, 0, 300, 20);
            // 左面图片
            CGPoint tempoint = CGPointMake(10, 25);
            CGSize size = CGSizeMake(300, 100);
            self.spoImageView.frame = (CGRect){tempoint,size};
            self.spoImageView.contentMode = UIViewContentModeScaleAspectFill;
            self.spoImageView.clipsToBounds = YES;
            // 内容标题
            self.sportsAccessibilityLabel.text = sports.digest;
            self.sportsAccessibilityLabel.frame = CGRectMake(10, CGRectGetMaxY(self.spoImageView.frame)-5 , 300, 40);
            self.sportsAccessibilityLabel.font = [UIFont systemFontOfSize:12.5         ];
            self.sportsAccessibilityLabel.textColor = [UIColor darkGrayColor];
            self.sportsAccessibilityLabel.numberOfLines = 0;
            self.sportsAccessibilityLabel.lineBreakMode = NSLineBreakByWordWrapping;
            self.techBottomLine.backgroundColor = [UIColor colorWithRed:200/255.0 green:200/255.0 blue:200/255.0 alpha:1.0];
            // 底部的线
            self.techBottomLine.frame = CGRectMake(0, CGRectGetMaxY(self.spoImageView.frame)+ 29.75, [UIScreen mainScreen].bounds.size.width, 0.75);
            
        }else{
            
            // 左面图片
            CGPoint tempoint = CGPointMake(10, 9.75);
            CGSize size = CGSizeMake(88.64, 65);
            self.spoImageView.frame = (CGRect){tempoint,size};
            self.spoImageView.contentMode = UIViewContentModeScaleAspectFill;
            self.spoImageView.clipsToBounds = YES;
            
            // 主标题
            self.titleLabel.text = sports.title;
            self.titleLabel.font = [UIFont systemFontOfSize:14.5];
            self.titleLabel.frame = CGRectMake(CGRectGetMaxX(self.spoImageView.frame) + 10, 10, [UIScreen mainScreen].bounds.size.width - 10 - CGRectGetMaxX(self.spoImageView.frame), 20);
            
            // 内容标题
            self.sportsAccessibilityLabel.text = sports.digest;
            self.sportsAccessibilityLabel.frame = CGRectMake(CGRectGetMaxX(self.spoImageView.frame) + 10, CGRectGetMaxY(self.titleLabel.frame), [UIScreen mainScreen].bounds.size.width - 10 - CGRectGetMaxX(self.spoImageView.frame) -10 ,50);
            self.sportsAccessibilityLabel.font = [UIFont systemFontOfSize:12.5         ];
            self.sportsAccessibilityLabel.textColor = [UIColor darkGrayColor];
            self.sportsAccessibilityLabel.numberOfLines = 0;
            self.sportsAccessibilityLabel.lineBreakMode = NSLineBreakByWordWrapping;
            self.techBottomLine.backgroundColor = [UIColor colorWithRed:200/255.0 green:200/255.0 blue:200/255.0 alpha:1.0];
            
            // 底部的线
            self.techBottomLine.frame = CGRectMake(0, CGRectGetMaxY(self.spoImageView.frame)+ 9.75, [UIScreen mainScreen].bounds.size.width, 0.75);
        }
    }
    
    
}- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
